import { DB } from "../entity";
import { ChromeList } from "../entity/ChromeList";
import { T_ChromeListItem } from "@shared/types/chromeList";
export const getChromeList = async () => {
  try {
    const data = await DB.getRepository(ChromeList).find();
    return {
      code: 0,
      data,
      message: "获取成功"
    };
  } catch (error) {
    return {
      code: -1,
      message: "获取失败",
      data: error
    };
  }
};
export const createChrome = async (data: T_ChromeListItem) => {
  try {
    await DB.getRepository(ChromeList).insert(data);
    return {
      code: 0,
      message: "创建成功"
    };
  } catch (err) {
    return {
      code: -1,
      message: "创建失败",
      data: err
    };
  }
};

export const updateChrome = async (id: string, data: T_ChromeListItem) => {
  try {
    await DB.getRepository(ChromeList).update(id, data);
    return {
      code: 0,
      message: "更新成功"
    };
  } catch (err) {
    return {
      code: -1,
      message: "更新失败",
      data: err
    };
  }
};

export const deleteChrome = async (id: string) => {
  try {
    await DB.getRepository(ChromeList).delete(id);
    return {
      code: 0,
      message: "删除成功"
    };
  } catch (err) {
    return {
      code: -1,
      message: "删除失败",
      data: err
    };
  }
};
